<template>
	<view class="content">
		<view class="header">
			<view class=""></view>
			<view class="header-right" @tap="$navTo('/pagesB/securityCheck/dangerReport')">
				<image src="/static/add.png" mode=""></image>
				<text>隐患上报</text>
			</view>
		</view>
		<view class="ipts">
			<view class="record">
				<view class="">
					<image src="/static/jilu.png" mode=""></image>
					<text>用户信息</text>
				</view>

			</view>
			<!-- 驳回 -->
			<view class="" v-if="status==='3'">
				<!-- 户号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查部门</text>
					</view>
					<input class="item-ipt" type="text" v-model="list_1.inspect" placeholder="检查部门名称" />
				</view>

				<!-- 户主姓名 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查人</text>
					</view>
					<input class="item-ipt" type="text" v-model="list_1.inspect_people" placeholder="请输入检查人" />
				</view>

				<!-- 身份证号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查地点</text>
					</view>
					<input class="item-ipt" type="text" v-model="list_1.inspect_place" placeholder="检查地点" />

				</view>

				<!-- 联系方式 -->
				<view class="info-item" @tap="shart">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查时间</text>
					</view>
					<input class="item-ipt" type="text" disabled v-model="list_1.inspect_time" placeholder="检查时间" />
				</view>
				<!-- 主要内容 -->
				<view class="handle">
					<view class="handle-item">
						<view class="dot"></view>
						<text>主要内容</text>
					</view>
					<textarea :disabled="disabled" v-model="list_1.content" type="text" placeholder="主要内容"
						placeholder-class="place-class" />
				</view>
				<!-- 检查事项 -->
				<view class="handle">
					<view class="handle-item">
						<view class="dot"></view>
						<text>检查事项</text>
					</view>
					<textarea :disabled="disabled" v-model="list_1.inspect_matter" type="text" placeholder="检查事项"
						placeholder-class="place-class" />
				</view>
				<!-- 检查记录 -->
				<view class="handle">
					<view class="handle-item">
						<view class="dot"></view>
						<text>检查记录</text>
					</view>
					<textarea :disabled="disabled" v-model="list_1.inspect_record" type="text" placeholder="检查记录"
						placeholder-class="place-class" />
				</view>
				<!-- 影像资料 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>影像资料</text>
					</view>
					<view class="addform-items">
						<view class="" style="position: relative;" v-for="(i,index) in list.video_data_files">
							<image class="form-img" :src="$img + i" :key="index" @tap="seeimg(index)"></image>
							<image class="delet" src="/static/delet.png" mode="" @tap="deletImg(index)"></image>
						</view>
						<view class="add" @tap="choosefrom">
							<u-icon name="camera" color="#999999" size="28"></u-icon>
						</view>
					</view>
				</view>
				<!-- 检查结果 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查结果</text>
					</view>
					<input class="item-ipt" type="text" v-model="list_1.inspect_result" placeholder="结果" />
				</view>
				<!-- 处理意见 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>处理意见</text>
					</view>
					<input class="item-ipt" type="text" v-model="list_1.opinion" placeholder="意见" />
				</view>
				<!-- 完成期限 -->
				<view class="info-item" @tap="end">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>完成期限</text>
					</view>
					<input class="item-ipt" type="text" disabled v-model="list_1.term_time" placeholder="完成期限" />
				</view>
				<!-- 驳回原因 -->
				<view class="handle">
					<view class="handle-item">
						<view class="dot"></view>
						<text>驳回原因</text>
					</view>
					<textarea :disabled="true" v-model="list_1.reason" type="text" placeholder="驳回原因"
						placeholder-class="place-class" />
				</view>
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>电子签名</text>
					</view>
					<view class="addform-items">
						<view class="" style="position: relative;" v-if="signature">
							<image class="form-img" :src="signature.intact_url" @tap="seek(signature.intact_url)">
							</image>
							<image class="delet" src="/static/delet.png" mode="" @tap="signDel()"></image>
						</view>
						<view class="add" @tap="$navTo('./sign')" v-if="signature==''">
							<u-icon name="plus" color="#999999" size="28"></u-icon>
						</view>
					</view>
				</view>

			</view>

			<!-- 正常 -->
			<view class="" v-if="addType === '1'">
				<!-- 户号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查部门</text>
					</view>
					<input class="item-ipt" type="text" v-model="list.inspect" placeholder="检查部门名称" />
				</view>

				<!-- 户主姓名 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查人</text>
					</view>
					<input class="item-ipt" type="text" v-model="list.inspect_people" placeholder="请输入检查人" />
				</view>

				<!-- 身份证号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查地点</text>
					</view>
					<input class="item-ipt" type="text" v-model="list.inspect_place" placeholder="检查地点" />

				</view>

				<!-- 联系方式 -->
				<view class="info-item" @tap="shart">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查时间</text>
					</view>
					<input class="item-ipt" type="text" disabled v-model="list.inspect_time" placeholder="检查时间" />
				</view>
				<!-- 主要内容 -->
				<view class="handle">
					<view class="handle-item">
						<view class="dot"></view>
						<text>主要内容</text>
					</view>
					<textarea :disabled="disabled" v-model="list.content" type="text" placeholder="主要内容"
						placeholder-class="place-class" />
				</view>
				<!-- 检查事项 -->
				<view class="handle">
					<view class="handle-item">
						<view class="dot"></view>
						<text>检查事项</text>
					</view>
					<textarea :disabled="disabled" v-model="list.inspect_matter" type="text" placeholder="检查事项"
						placeholder-class="place-class" />
				</view>
				<!-- 检查记录 -->
				<view class="handle">
					<view class="handle-item">
						<view class="dot"></view>
						<text>检查记录</text>
					</view>
					<textarea :disabled="disabled" v-model="list.inspect_record" type="text" placeholder="检查记录"
						placeholder-class="place-class" />
				</view>
				<!-- 影像资料 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>影像资料</text>
					</view>
					<view class="addform-items">
						<view class="" style="position: relative;" v-for="(i,index) in list.video_data_files">
							<image class="form-img" :src="$img + i" :key="index" @tap="seeimg(index)"></image>
							<image class="delet" src="/static/delet.png" mode="" @tap="deletImg(index)"></image>
						</view>
						<view class="add" @tap="choosefrom">
							<u-icon name="camera" color="#999999" size="28"></u-icon>
						</view>
					</view>
				</view>
				<!-- 检查结果 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>检查结果</text>
					</view>
					<input class="item-ipt" type="text" v-model="list.inspect_result" placeholder="结果" />
				</view>
				<!-- 处理意见 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>处理意见</text>
					</view>
					<input class="item-ipt" type="text" v-model="list.opinion" placeholder="意见" />
				</view>
				<!-- 完成期限 -->
				<view class="info-item" @tap="end">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>完成期限</text>
					</view>
					<input class="item-ipt" type="text" disabled v-model="list.term_time" placeholder="完成期限" />
				</view>
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<text>电子签名</text>
					</view>
					<view class="addform-items">
						<view class="" style="position: relative;" v-if="signature">
							<image class="form-img" :src="signature.intact_url" @tap="seek(signature.intact_url)">
							</image>
							<image class="delet" src="/static/delet.png" mode="" @tap="signDel()"></image>
						</view>
						<view class="add" @tap="$navTo('./sign')" v-if="signature==''">
							<u-icon name="plus" color="#999999" size="28"></u-icon>
						</view>
					</view>
				</view>

			</view>



		</view>
		<!-- <view class="history" @tap="$navTo('/pagesB/rithcheck/meterList')">
			<image class="historyicon" src="/static/jilu.png" mode=""></image>
			<text class="text">安检记录</text>
		</view> -->
		<view class="btns">
			<view class="btn1 consel" @click="cancel">取消</view>
			<view class="btn1 save" v-if="!list_1.status" @click="userPost">保存</view>
			<view class="btn1 save" v-if="list_1.status == 3" @click="anewUserPost">保存</view>
		</view>

		<u-picker v-model="show" mode="time" @confirm="confirm" :params="params"></u-picker>


	</view>
</template>

<script>
	import cpimg from "@/components/cpimg/cpimg.vue"
	import easySelect from '@/components/easy-select/easy-select'
	export default {
		components: {
			easySelect,
			cpimg
		},
		data() {
			return {
				user_info: '',
				last_check: '',
				searchIpt: '',
				flag: true,
				show: false,
				time: true,
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false,
				},
				list: {
					inspect_time: '',
					term_time: '',
					inspect: '', //检查部门
					inspect_people: '', //检查人
					inspect_place: '', //检查地点
					content: '', //主要内容
					inspect_matter: '', //检查事项
					inspect_record: '', //检查记录
					inspect_result: '', //检查结果
					opinion: '', //处理意见
					video_data_files: [], //影像资料
					sign: '', //电子签名
					danger_id: [] //隐患关联的id
				},
				list_1: {
					inspect: '', // 检查部门
					inspect_people: '', //检查人
					inspect_place: '', // 检查地点
					inspect_time: '', //检查时间
					content: '', //主要内容
					inspect_matter: '', //检查事项
					inspect_record: '', //检查记录
					inspect_result: '', //检查结果
					opinion: '', //处理意见
					term_time: '', //完成期限
					video_data_files: [], //影像资料
					sign: '', //电子签名
				},
				signature: '',
				token: '',
				$img: 'https://trq.wqzsgas.com',
				sercode: [],
				status: 3,
				addType: ''
			}
		},
		onShow() {

			this.token = uni.getStorageSync('token')
		},
		onLoad(e) {
			// this.init(e)
			// this.token = e.token
			console.log('eee', e);
			if (e.status === '3') {
				this.status = e.status
				this.getDetails(e.id)
			}
			if (e.addType === '1') {
				this.addType = e.addType
			}
			wx.enableAlertBeforeUnload({
				message: "是否返回上一页",
			});
		},
		methods: {
			getDetails(id) {
				var _this = this
				uni.request({
					url: _this.$url + 'staff.Inspect/details',
					method: 'GET',
					data: {
						id: id
					},
					success: (res) => {
						console.log('res', res);
						if (res.data.code == 0) {
							return _this.$showToast(res.data.msg)
						}
						_this.list_1 = res.data.data
						_this.list_1.id = id
						_this.list.video_data_files = _this.list_1.video_data_files
					}
				})
			},
			// 重新提交保存
			anewUserPost() {
				let _this = this
				if (this.signature.url) {
					this.list.sign = this.signature.url
					this.list_1.sign = this.signature.url
				}
				if (!this.list_1.inspect) return this.$showToast('请输入检查部门名称')
				if (!this.list_1.inspect_people) return this.$showToast('请输入检查人')
				if (!this.list_1.inspect_place) return this.$showToast('请输入检查地点')
				if (!this.list_1.inspect_time) return this.$showToast('请选择检查时间')
				if (!this.list_1.content) return this.$showToast('请输入主要内容')
				if (!this.list_1.inspect_matter) return this.$showToast('请输入检查事项')
				if (!this.list_1.inspect_record) return this.$showToast('请输入检查记录')
				if (!this.list_1.inspect_result) return this.$showToast('请输入检查结果')
				if (!this.list_1.opinion) return this.$showToast('请输入处理意见')
				if (!this.list_1.term_time) return this.$showToast('请输入完成期限')
				if (!this.list_1.sign) return this.$showToast('请输入电子签名')

				this.$set(this.list_1, 'token', this.token)
				// this.$set(this.list,'user_id',this.user_info.id)
				this.list_1.danger_id = this.sercode
				console.log('this.list_1.inspect_time', this.list_1.inspect_time);

				uni.request({
					url: this.$url + 'staff.Inspect/editinspcet',
					method: "POST",
					header: {
						token: uni.getStorageSync('token')
					},
					data: _this.list_1,
					success: (res) => {
						console.log('_this.list_1', _this.list_1);
						_this.$showToast(res.data.msg)
						// if(res.data.code == 1){
						// 	setTimeout(()=>{
						// 		uni.navigateBack({
						// 			delta:1
						// 		})
						// 	},1000)
						// }
					}
				})

			},
			// 提交保存
			userPost() {
				let _this = this
				if (this.signature.url) {
					this.list.sign = this.signature.url
					this.list_1.sign = this.signature.url
				}
				if (!this.list.inspect) return this.$showToast('请输入检查部门名称')
				if (!this.list.inspect_people) return this.$showToast('请输入检查人')
				if (!this.list.inspect_place) return this.$showToast('请输入检查地点')
				if (!this.list.inspect_time) return this.$showToast('请选择检查时间')
				if (!this.list.content) return this.$showToast('请输入主要内容')
				if (!this.list.inspect_matter) return this.$showToast('请输入检查事项')
				if (!this.list.inspect_record) return this.$showToast('请输入检查记录')
				if (!this.list.inspect_result) return this.$showToast('请输入检查结果')
				if (!this.list.opinion) return this.$showToast('请输入处理意见')
				if (!this.list.term_time) return this.$showToast('请输入完成期限')
				if (!this.list.sign) return this.$showToast('请输入电子签名')
				console.log('this.list.inspect_time', this.list.inspect_time);
				this.$set(this.list, 'token', this.token)
				// this.$set(this.list,'user_id',this.user_info.id)
				this.list.danger_id = this.sercode
				uni.request({
					url: this.$url + 'staff.Inspect/security',
					method: "POST",
					header: {
						token: uni.getStorageSync('token')
					},
					data: _this.list,
					success: (res) => {
						console.log('_this.list', _this.list);
						_this.$showToast(res.data.msg)
						// if(res.data.code == 1){
						// 	setTimeout(()=>{
						// 		uni.navigateBack({
						// 			delta:1
						// 		})
						// 	},1000)
						// }
					}
				})

			},
			choosefrom() {
				if (this.list.video_data_files.length < 4) {
					var _this = this
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							uni.uploadFile({
								url: _this.$fileImg + 'common/upload',
								filePath: res.tempFilePaths[0],
								name: 'file',
								header: this._header,
								formData: {
									token: this.token
								},
								success: (uploadFileRes) => {
									console.log(JSON.parse(uploadFileRes.data), '00000');
									if (JSON.parse(uploadFileRes.data).code == 1) {
										this.list.video_data_files.push(JSON.parse(uploadFileRes
												.data).data
											.url)
									}
								},
								fail: (err) => {
									console.log(err);
								}
							})
						},
						fail: (err) => {
							console.log(err);
						}
					})
				} else {
					this.$showToast('上传已达到限制')
				}
			},
			seeimg(index) {
				let url = 'https://trq.wqzsgas.com';
				let arr = []
				for (let i = 0; i < this.list.video_data_files.length; i++) {
					arr.push(url + this.list.video_data_files[i])
				}
				uni.previewImage({
					urls: arr,
					current: index,
					loop: true
				})
			},
			seek(img) {
				uni.previewImage({
					urls: [img]
				})
			},
			signDel() {
				this.signature = ''
			},
			deletImg(index) {
				console.log('index', index);
				this.list.video_data_files.splice(index, 1)
			},
			// init(e) {
			// 	let that = this
			// 	uni.request({
			// 		url: that.$url + 'staff.Inspect/searchUser',
			// 		method: 'POST',
			// 		header: {
			// 			token: e.token,
			// 		},
			// 		data: {
			// 			token: e.token,
			// 			meter_num: e.meter_num
			// 		},
			// 		success: (res) => {
			// 			if (res.data.code == 1) {
			// 				that.user_info = res.data.data.user_info
			// 				that.last_check = res.data.data.last_check
			// 				that.flag = false;
			// 			} else {
			// 				that.$showToast(res.data.msg)
			// 				that.flag = true
			// 				that.searchIpt = ''
			// 			}
			// 		}
			// 	})
			// },
			shart() {
				this.show = true
				this.time = true
				console.log('this.time', this.time);
			},
			end() {
				this.show = true
				this.time = false
			},
			cancel() {
				uni.navigateBack({
					delta: 1
				})
			},
			confirm(e) {
				if (this.time) {
					this.list.inspect_time = e.year + '-' + e.month + '-' + e.day
					this.list_1.inspect_time = e.year + '-' + e.month + '-' + e.day
					console.log('this.list.inspect_time', this.list.inspect_time);
					console.log('this.list_1.inspect_time', this.list_1.inspect_time);
				} else {
					this.list.term_time = e.year + '-' + e.month + '-' + e.day
					this.list_1.term_time = e.year + '-' + e.month + '-' + e.day
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.history {
		margin-top: 18rpx;
		padding: 20rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;

		.historyicon {
			width: 33rpx;
			height: 32rpx;
		}

		.text {
			margin-left: 12rpx;
			font-size: 28rpx;
			font-family: Source Han Sans SC;
			font-weight: 500;
			color: #003690;
		}
	}

	.content {
		background: #F1F1F1;
		padding-bottom: 100rpx;

		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			// padding: 30rpx 30rpx;
			background-color: #F1F1F1;

			.header-right {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				color: #333;
				// margin-right: 20rpx;
				padding: 10rpx 30rpx;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}
			}
		}

		.header1 {
			display: flex;
			align-items: center;
			box-sizing: border-box;
			height: 80rpx;
			width: 100%;
			background-color: #003690;
			padding: 0 30rpx;

			.ipt-box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				box-sizing: border-box;
				padding: 0 20rpx;
				width: 450rpx;
				height: 52rpx;
				background-color: #fff;
				border-radius: 24rpx;

				image {
					width: 32rpx;
					height: 32rpx;
				}
			}

			.header1-right {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				color: #E2ECFB;
				flex: 1;
				justify-content: center;

				image {
					width: 36rpx;
					height: 36rpx;
				}
			}
		}

		.newstyle {
			background: #003690;
			color: #FFFFFF;
		}



		.btns {
			position: fixed;
			bottom: 0;
			display: flex;
			width: 100%;
			z-index: 333;

			.btn1 {
				width: 50%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				font-size: 24rpx;
			}

			.consel {
				background-color: #e9e9e9;
				color: #777;
			}

			.save {
				background-color: #003690;
				color: #fff;
			}
		}

		.btn:active {
			background: rgba(0, 0, 0, 0.4);
		}

		.zhanwei {
			height: 250rpx;
		}

		.ipts {
			background-color: #fff;
			margin-bottom: 20rpx;

			.record {
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #003690;
				font-size: 32rpx;
				padding-top: 20rpx;

				.right {
					width: 394rpx;
					height: 52rpx;
					background: #F2F2F2;
					opacity: 1;
					border-radius: 50rpx;
				}

				image {
					width: 32rpx;
					height: 32rpx;
					margin: 0 20rpx 0 30rpx;
				}
			}


			.liaison {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10rpx 30rpx;

				.left {
					display: flex;
					align-items: center;

					.shuxian {
						width: 8rpx;
						height: 28rpx;
						background: #003690;
						opacity: 1;
						border-radius: 200rpx;
						margin-right: 10rpx;
					}

					.name {
						font-size: 28rpx;
						font-family: Source Han Sans SC;
						font-weight: 500;
						color: #333333;
						margin-right: 10rpx;
					}

					.time {
						font-size: 24rpx;
						font-family: Source Han Sans SC;
						font-weight: 400;
						color: #777777;
					}
				}

				.right {
					display: flex;
					align-items: center;

					image {
						width: 32rpx;
						height: 32rpx;
						margin-right: 10rpx;
					}

					.phone {
						font-size: 24rpx;
						font-family: Source Han Sans SC;
						font-weight: 400;
						color: #555555;
					}
				}
			}
		}

		.info-item {
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			// height: 72rpx;
			width: 100%;
			height: 100rpx;
			padding: 0rpx 32rpx;
			align-items: center;
			background-color: #fff;
			font-size: 24rpx;
			color: #333;
			border-bottom: 1rpx solid #DDDDDD;

			image {
				width: 32rpx;
				height: 32rpx;
			}

			input {
				flex: 1;
				text-align: right;
			}

			.dot {
				width: 8rpx;
				height: 8rpx;
				background-color: #003690;
				border-radius: 50%;
				margin-right: 10rpx;
			}

			.danger-img {
				position: relative;

				.updeletes {
					position: absolute;
					top: -20rpx;
					right: -20rpx;
					width: 40rpx;
					height: 40rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					z-index: 88;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.danger-img-box {
				display: flex;

				.danger-img {
					width: 75rpx;
					height: 75rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.danger-img-box2 {
				display: flex;

				.danger-img {
					width: 75rpx;
					height: 75rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;

					image {
						width: 100%;
						height: 100%;
						opacity: 1;
					}
				}
			}

			.info-item-left {
				display: flex;
				align-items: center;
				font-size: 28rpx;
			}

			.addform-items {
				display: flex;
				align-items: center;

				.delet {
					position: absolute;
					top: -8rpx;
					right: 4rpx;
					width: 28rpx;
					height: 28rpx;
					z-index: 10;
				}

				.form-img {
					width: 60rpx;
					height: 60rpx;
					margin-right: 20rpx;
				}

				.add {
					width: 60rpx;
					height: 60rpx;
					border: 1rpx solid #DDDDDD;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}

	}

	.place-class {
		font-size: 26rpx;
		color: #999;
	}

	.handle {
		box-sizing: border-box;
		display: grid;
		grid-template-columns: 150rpx auto;
		align-items: center;
		// height: 72rpx;
		width: 100%;
		padding: 32rpx 32rpx;
		align-items: center;
		background-color: #fff;
		font-size: 28rpx;
		color: #333;
		border-bottom: 1rpx solid #DDDDDD;
		word-break: break-all;

		.handle-item {
			display: flex;
			align-items: center;
		}

		.handle-text {
			// flex: 1;
			word-break: break-all;
			word-wrap: break-word;
			text-align: right;
			color: #333333;
			font-size: 28rpx;
		}

		.dot {
			width: 8rpx;
			height: 8rpx;
			background-color: #003690;
			border-radius: 50%;
			margin-right: 10rpx;
		}

		textarea {
			width: 550rpx;
		}
	}
</style>
